package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.Banner;
import cn.anxingongyou.anxin.mapper.BannerMapper;
import cn.anxingongyou.anxin.service.BannerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {

    private final BannerMapper bannerMapper;
    @Autowired
    public BannerServiceImpl(BannerMapper bannerMapper) {
        this.bannerMapper = bannerMapper;
    }

    @Override
    public int insert(Banner banner) {
        return bannerMapper.insertSelective(banner);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return bannerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Banner banner) {
        return bannerMapper.updateByPrimaryKeySelective(banner);
    }

    @Override
    public Banner selectOne(Banner banner) {
        return bannerMapper.selectOne(banner);
    }

    @Override
    public Banner selectOneByPrimaryKey(Long id) {
        return bannerMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Banner> page(int pageNum, int pageSize, Banner banner) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<Banner> list = bannerMapper.select(banner);
        PageInfo<Banner> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
